package com.nc.shop.service.controller;

import com.nc.shop.service.dao.LandDao;
import com.nc.shop.service.dao.LandLeanDao;
import com.nc.shop.service.model.dto.LandLeanDto;
import com.nc.shop.service.model.entity.LandEntity;
import com.nc.shop.service.model.entity.LandLeanEntity;
import com.nc.shop.service.service.LandService;
import com.plug.BeanUtil;
import com.plug.result.ReqPage;
import com.plug.result.RetResponse;
import com.plug.result.RetResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 创建人:    xvzhe
 * 创建时间:
 * 修改时间:
 * 版本:      v1.0
 */
@RestController
@RequestMapping("LandController")
@Api
public class LandController {
    @Autowired
    LandService landService;
    @Autowired
    LandDao landDao;
    @Autowired
    LandLeanDao landLeanDao;

    @PostMapping("getLand")
    @ApiOperation("土地列表")
    public RetResult getLand(@RequestBody ReqPage reqPage) {
        return landService.findPage(reqPage);
    }

    @PostMapping("land")
    @ApiOperation("保存土地")
    public RetResult land(@RequestBody LandEntity landEntity) {
        landDao.save(landEntity);
        return RetResponse.makeOKRsp();
    }

    @PostMapping("getLandLean")
    @ApiOperation("土地租借记录")
    public RetResult getLandLean(@RequestBody ReqPage reqPage) {
        return landService.findLeanPage(reqPage);
    }

    @PostMapping("landLean")
    @ApiOperation("保存土地租借记录")
    public RetResult landLean(@RequestBody LandLeanDto landLeanDto) {
        LandLeanEntity landLeanEntity = BeanUtil.convertToBean(landLeanDto, LandLeanEntity.class);
        landLeanEntity.setLandEntity(landDao.findById(landLeanDto.getLandId()).get());
        landLeanEntity.setStatus(true);
        landLeanDao.save(landLeanEntity);
        return RetResponse.makeOKRsp();
    }
}
